class GenreateSurveys < ActiveRecord::Migration
  def self.up
  	
  	creationDate = ['2009-03-02', '2009-03-12','2009-03-22'", "'2009-04-02', '2009-05-02'];
  	startDate = ['2009-05-03','2009-06-03','2009-05-21','2009-06-13' ];
  	endDate = ['2009-06-23','2009-07-03','2009-07-21','2009-07-13' ];
  
  	editionperm_id=SurveyPermissionType.find_by_name('edition').id
	statsperm_id=SurveyPermissionType.find_by_name('stats').id
	
  		
  	@users=Hash.new
  	i=0
  	for user in User.find(:all)
  		@users[i]=user.id
  		i+=1
  	end
	
  	0.upto(60) do |x|
  		userid=@users[rand(@users.length)]
		@Survey=Survey.new(:title => 'survey'<<(x+1).to_s,:description=>'desc of survey'<<(x+1).to_s,:creation_date=>creationDate[rand(creationDate.length)],
		:start_date=>startDate[rand(startDate.length)],:end_date=>endDate[rand(endDate.length)],:anonymous=>'y',:ready=>'y',
		:userID=>userid
  		)
  		@Survey.save!
  		UsersSurveysPermission.create(:survey_id=>@Survey.id,:permission_type_id=>editionperm_id,:user_id=>userid)	
  		UsersSurveysPermission.create(:survey_id=>@Survey.id,:permission_type_id=>statsperm_id,:user_id=>userid)	
  		
	end
	
  end

  def self.down
  	Survey.delete_all 	
  	UsersSurveysPermission.delete_all
  end
end
